import type { Reward } from '../../model/reward/type';
import { type Condition } from '../../systems/condition-checker/type';

export const SECT_TAG = {
  /** 公共 */
  COMMON: 'COMMON',
  /** 炼丹 */
  LIAN_DAN: 'LIAN_DAN',
  /** 炼器 */
  LIAN_QI: 'LIAN_QI',
} as const;

export type SectTag = (typeof SECT_TAG)[keyof typeof SECT_TAG];

export const SECT_LEVEL = {
  /** 一阶门派 */
  SECT_LEVEL_01: 'SECT_LEVEL_01',
  /** 二阶门派 */
  SECT_LEVEL_02: 'SECT_LEVEL_02',
  /** 三阶门派 */
  SECT_LEVEL_03: 'SECT_LEVEL_03',
  /** 四阶门派 */
  SECT_LEVEL_04: 'SECT_LEVEL_04',
  /** 五阶门派 */
  SECT_LEVEL_05: 'SECT_LEVEL_05',
  /** 六阶门派 */
  SECT_LEVEL_06: 'SECT_LEVEL_06',
  /** 七阶门派 */
  SECT_LEVEL_07: 'SECT_LEVEL_07',
  /** 八阶门派 */
  SECT_LEVEL_08: 'SECT_LEVEL_08',
  /** 九阶门派 */
  SECT_LEVEL_09: 'SECT_LEVEL_09',
  /** 黄阶门派 */
  SECT_LEVEL_HUANG: 'SECT_LEVEL_HUANG',
  /** 玄阶门派 */
  SECT_LEVEL_XUAN: 'SECT_LEVEL_XUAN',
  /** 地阶门派 */
  SECT_LEVEL_DI: 'SECT_LEVEL_DI',
  /** 天阶门派 */
  SECT_LEVEL_TIAN: 'SECT_LEVEL_TIAN',
} as const;

export type SectLevel = (typeof SECT_LEVEL)[keyof typeof SECT_LEVEL];

export const SECT_LEVEL_NUMBER: Record<SectLevel, number> = {
  [SECT_LEVEL.SECT_LEVEL_01]: 1,
  [SECT_LEVEL.SECT_LEVEL_02]: 2,
  [SECT_LEVEL.SECT_LEVEL_03]: 3,
  [SECT_LEVEL.SECT_LEVEL_04]: 4,
  [SECT_LEVEL.SECT_LEVEL_05]: 5,
  [SECT_LEVEL.SECT_LEVEL_06]: 6,
  [SECT_LEVEL.SECT_LEVEL_07]: 7,
  [SECT_LEVEL.SECT_LEVEL_08]: 8,
  [SECT_LEVEL.SECT_LEVEL_09]: 9,
  [SECT_LEVEL.SECT_LEVEL_HUANG]: 10,
  [SECT_LEVEL.SECT_LEVEL_XUAN]: 11,
  [SECT_LEVEL.SECT_LEVEL_DI]: 12,
  [SECT_LEVEL.SECT_LEVEL_TIAN]: 13,
};

export const SECT_LEVEL_DESC: Record<SectLevel, string> = {
  [SECT_LEVEL.SECT_LEVEL_01]: '一阶门派',
  [SECT_LEVEL.SECT_LEVEL_02]: '二阶门派',
  [SECT_LEVEL.SECT_LEVEL_03]: '三阶门派',
  [SECT_LEVEL.SECT_LEVEL_04]: '四阶门派',
  [SECT_LEVEL.SECT_LEVEL_05]: '五阶门派',
  [SECT_LEVEL.SECT_LEVEL_06]: '六阶门派',
  [SECT_LEVEL.SECT_LEVEL_07]: '七阶门派',
  [SECT_LEVEL.SECT_LEVEL_08]: '八阶门派',
  [SECT_LEVEL.SECT_LEVEL_09]: '九阶门派',
  [SECT_LEVEL.SECT_LEVEL_HUANG]: '黄阶门派',
  [SECT_LEVEL.SECT_LEVEL_XUAN]: '玄阶门派',
  [SECT_LEVEL.SECT_LEVEL_DI]: '地阶门派',
  [SECT_LEVEL.SECT_LEVEL_TIAN]: '天阶门派',
};

export const SECT_LEVEL_MULTIPLIER: Record<SectLevel, number> = {
  [SECT_LEVEL.SECT_LEVEL_01]: 1.0,
  [SECT_LEVEL.SECT_LEVEL_02]: 1.2,
  [SECT_LEVEL.SECT_LEVEL_03]: 1.4,
  [SECT_LEVEL.SECT_LEVEL_04]: 1.6,
  [SECT_LEVEL.SECT_LEVEL_05]: 1.8,
  [SECT_LEVEL.SECT_LEVEL_06]: 2.0,
  [SECT_LEVEL.SECT_LEVEL_07]: 2.2,
  [SECT_LEVEL.SECT_LEVEL_08]: 2.4,
  [SECT_LEVEL.SECT_LEVEL_09]: 2.6,
  [SECT_LEVEL.SECT_LEVEL_HUANG]: 3.0,
  [SECT_LEVEL.SECT_LEVEL_XUAN]: 3.5,
  [SECT_LEVEL.SECT_LEVEL_DI]: 4.0,
  [SECT_LEVEL.SECT_LEVEL_TIAN]: 5.0,
};

export const SECT_JOB = {
  /** 杂役弟子 */
  OUTER_SERVANT: 'OUTER_SERVANT',
  /** 外门弟子 */
  OUTER_DISCIPLE: 'OUTER_DISCIPLE',
  /** 内门弟子 */
  INNER_DISCIPLE: 'INNER_DISCIPLE',
  /** 真传弟子 */
  TRUE_DISCIPLE: 'TRUE_DISCIPLE',
  /** 执事 */
  MANAGER: 'MANAGER',
  /** 长老 */
  ELDER: 'ELDER',
  /** 太上长老 */
  SUPER_ELDER: 'SUPER_ELDER',
} as const;

export type SectJob = keyof typeof SECT_JOB;

export const SECT_JOB_NUMBER: Record<SectJob, number> = {
  [SECT_JOB.OUTER_SERVANT]: 1,
  [SECT_JOB.OUTER_DISCIPLE]: 2,
  [SECT_JOB.INNER_DISCIPLE]: 3,
  [SECT_JOB.TRUE_DISCIPLE]: 4,
  [SECT_JOB.MANAGER]: 5,
  [SECT_JOB.ELDER]: 6,
  [SECT_JOB.SUPER_ELDER]: 7,
};

export interface SectJobConfig {
  /** 职位 ID */
  id: SectJob;
  /** 职位名称 */
  name: string;
  /** 职位等级 */
  level: number;
  /** 职位系数 */
  multiplier: number;
  /** 下一级职位所需贡献度 */
  nextContribution?: number;
}

export const SECT_JOB_DATA: SectJobConfig[] = [
  {
    id: SECT_JOB.OUTER_SERVANT,
    name: '杂役弟子',
    level: 1,
    multiplier: 1.0,
    nextContribution: 500,
  },
  {
    id: SECT_JOB.OUTER_DISCIPLE,
    name: '外门弟子',
    level: 2,
    multiplier: 1.2,
    nextContribution: 1000,
  },
  {
    id: SECT_JOB.INNER_DISCIPLE,
    name: '内门弟子',
    level: 3,
    multiplier: 1.5,
    nextContribution: 2000,
  },
  {
    id: SECT_JOB.TRUE_DISCIPLE,
    name: '真传弟子',
    level: 4,
    multiplier: 1.9,
    nextContribution: 4000,
  },
  {
    id: SECT_JOB.MANAGER,
    name: '执事',
    level: 5,
    multiplier: 2.4,
    nextContribution: 8000,
  },
  {
    id: SECT_JOB.ELDER,
    name: '长老',
    level: 6,
    multiplier: 3.0,
    nextContribution: 16000,
  },
  {
    id: SECT_JOB.SUPER_ELDER,
    name: '太上长老',
    level: 7,
    multiplier: 4.0,
  },
];

/** 宗门任务类型 */
export const SECT_TASK_TYPE = {
  /** 挂机任务 */
  HANG_UP: 'HANG_UP',
  /** 普通任务 */
  NORMAL: 'NORMAL',
} as const;

export type SectTaskType = keyof typeof SECT_TASK_TYPE;

interface BaseSectTaskConfig {
  id: string;
  name: string;
  description: string;
  type: SectTaskType;
  /** 专属于哪个标签的宗门 */
  tag: SectTag;
  /** 任务基础奖励(结算根据系数计算) */
  baseReward: Reward[];
  /** 完成任务条件 */
  conditions?: Condition[];
  /** 领取任务条件 */
  receiveConditions?: Condition[];
}

export interface HangUpSectTaskConfig extends BaseSectTaskConfig {
  type: typeof SECT_TASK_TYPE.HANG_UP;
}

export interface NormalSectTaskConfig extends BaseSectTaskConfig {
  type: typeof SECT_TASK_TYPE.NORMAL;
}

export type SectTaskConfig = HangUpSectTaskConfig | NormalSectTaskConfig;

export interface SectCultivationSpotConfig {
  id: string;
  name: string;
  description: string;
  level: SectLevel;
  /** 修炼效率加成 */
  cultivationMultiplier: number;
  /** 灵石消耗 */
  stoneConsumption: number;
}

export const SECT_CULTIVATION_SPOT_ID = {
  /** 聚气庭院 */
  SECT_CULTIVATION_SPOT_01: 'SECT_CULTIVATION_SPOT_01',
  /** 灵气阁楼 */
  SECT_CULTIVATION_SPOT_02: 'SECT_CULTIVATION_SPOT_02',
  /** 凝露台 */
  SECT_CULTIVATION_SPOT_03: 'SECT_CULTIVATION_SPOT_03',
  /** 灵石密室 */
  SECT_CULTIVATION_SPOT_04: 'SECT_CULTIVATION_SPOT_04',
  /** 五行洞府 */
  SECT_CULTIVATION_SPOT_05: 'SECT_CULTIVATION_SPOT_05',
  /** 星辰观天台 */
  SECT_CULTIVATION_SPOT_06: 'SECT_CULTIVATION_SPOT_06',
  /** 龙脉福地 */
  SECT_CULTIVATION_SPOT_07: 'SECT_CULTIVATION_SPOT_07',
  /** 九转玄洞 */
  SECT_CULTIVATION_SPOT_08: 'SECT_CULTIVATION_SPOT_08',
  /** 万象归一殿 */
  SECT_CULTIVATION_SPOT_09: 'SECT_CULTIVATION_SPOT_09',
  /** 黄泉悟道崖 */
  SECT_CULTIVATION_SPOT_HUANG: 'SECT_CULTIVATION_SPOT_HUANG',
  /** 玄天秘境 */
  SECT_CULTIVATION_SPOT_XUAN: 'SECT_CULTIVATION_SPOT_XUAN',
  /** 地心熔炉 */
  SECT_CULTIVATION_SPOT_DI: 'SECT_CULTIVATION_SPOT_DI',
  /** 天道祭坛 */
  SECT_CULTIVATION_SPOT_TIAN: 'SECT_CULTIVATION_SPOT_TIAN',
} as const;

export const SECT_CULTIVATION_SPOTS_DATA: Record<
  SectLevel,
  SectCultivationSpotConfig
> = {
  /** 一阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_01]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_01,
    name: '聚气庭院',
    description: '初入仙门的弟子在此感受天地灵气，基础打坐修炼之所',
    level: SECT_LEVEL.SECT_LEVEL_01,
    cultivationMultiplier: 1.04,
    stoneConsumption: 1000,
  },
  /** 二阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_02]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_02,
    name: '灵气阁楼',
    description: '二层阁楼，灵气较庭院更为浓郁，适合炼气期弟子修炼',
    level: SECT_LEVEL.SECT_LEVEL_02,
    cultivationMultiplier: 1.08,
    stoneConsumption: 2000,
  },
  /** 三阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_03]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_03,
    name: '凝露台',
    description: '高台之上，晨露凝华，有助于凝练真气',
    level: SECT_LEVEL.SECT_LEVEL_03,
    cultivationMultiplier: 1.12,
    stoneConsumption: 3000,
  },
  /** 四阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_04]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_04,
    name: '灵石密室',
    description: '以灵石构筑的修炼室，灵气充沛稳定',
    level: SECT_LEVEL.SECT_LEVEL_04,
    cultivationMultiplier: 1.16,
    stoneConsumption: 4000,
  },
  /** 五阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_05]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_05,
    name: '五行洞府',
    description: '依五行相生之理建造，平衡体内五行之气',
    level: SECT_LEVEL.SECT_LEVEL_05,
    cultivationMultiplier: 1.2,
    stoneConsumption: 5000,
  },
  /** 六阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_06]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_06,
    name: '星辰观天台',
    description: '夜观星辰，感悟天道，筑基弟子的最佳修炼地',
    level: SECT_LEVEL.SECT_LEVEL_06,
    cultivationMultiplier: 1.24,
    stoneConsumption: 6000,
  },
  /** 七阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_07]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_07,
    name: '龙脉福地',
    description: '建于灵脉支流之上，灵气如龙游走',
    level: SECT_LEVEL.SECT_LEVEL_07,
    cultivationMultiplier: 1.28,
    stoneConsumption: 7000,
  },
  /** 八阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_08]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_08,
    name: '九转玄洞',
    description: '洞中九转，每转灵气倍增，金丹修士的修炼圣地',
    level: SECT_LEVEL.SECT_LEVEL_08,
    cultivationMultiplier: 1.32,
    stoneConsumption: 8000,
  },
  /** 九阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_09]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_09,
    name: '万象归一殿',
    description: '万法归宗，万象归一，元婴修士在此寻求突破',
    level: SECT_LEVEL.SECT_LEVEL_09,
    cultivationMultiplier: 1.36,
    stoneConsumption: 9000,
  },
  /** 黄阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_HUANG]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_HUANG,
    name: '黄泉悟道崖',
    description: '崖临黄泉，生死之间感悟大道真谛',
    level: SECT_LEVEL.SECT_LEVEL_HUANG,
    cultivationMultiplier: 1.4,
    stoneConsumption: 10000,
  },
  /** 玄阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_XUAN]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_XUAN,
    name: '玄天秘境',
    description: '自成一方小世界，时间流速与外界不同',
    level: SECT_LEVEL.SECT_LEVEL_XUAN,
    cultivationMultiplier: 1.44,
    stoneConsumption: 11000,
  },
  /** 地阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_DI]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_DI,
    name: '地心熔炉',
    description: '引地心之火锤炼元神，化神期修士专用',
    level: SECT_LEVEL.SECT_LEVEL_DI,
    cultivationMultiplier: 1.48,
    stoneConsumption: 12000,
  },
  /** 天阶门派修炼地 */
  [SECT_LEVEL.SECT_LEVEL_TIAN]: {
    id: SECT_CULTIVATION_SPOT_ID.SECT_CULTIVATION_SPOT_TIAN,
    name: '天道祭坛',
    description: '直通天道，与天地共鸣，渡劫修士的最终修炼地',
    level: SECT_LEVEL.SECT_LEVEL_TIAN,
    cultivationMultiplier: 1.52,
    stoneConsumption: 13000,
  },
};

export interface SectScriptureHallConfig {
  /** 需要的宗门贡献 */
  contribution: number;
  /** 奖励 */
  reward: Reward;
  /** 兑换条件 */
  exchangeCondition?: Condition[];
}

export interface SectConfig {
  id: string;
  name: string;
  description: string;
  /** 宗门阶级 */
  level: SectLevel;
  /** 宗门标签(比如炼丹、炼器) */
  tags: Set<SectTag>;
  /** 加入宗门需要的条件 */
  conditions?: Condition[];
  /** 独家宗门任务 */
  exclusiveTasks?: string[];
  /** 藏书阁 */
  scriptureHall: SectScriptureHallConfig[];
}
